<?php
session_start();
include "./public/common/config.php";
include "./public/common/function.php";

if($_POST){
	print_r($_POST);
	print_r($_FILES);
	
	$nick = $_POST['nick'];
	$tel = $_POST['tel'];
	$email = $_POST['email'];
	$gender = $_POST['gender'];
	$des = $_POST['des'];
	$id = $_SESSION['home_userid'];
	
	//图片上传
	$src = $_FILES['img']['tmp_name'];
	$fname = $_FILES['img']['name'];
	$a = explode('.',$fname);
	$ext = array_pop($a);
	$dst = './img/'.time().mt_rand().'.'.$ext;
	
	//如果图片上传成功，则生成缩略图
	if(move_uploaded_file($src,$dst)){
		//进行图片缩放200X200
		thumb($dst,200,200);
		$img = basename($dst);
		
		$sql = "update user set nick='{$nick}',tel='{$tel}',email='{$email}',gender='{$gender}',des='{$des}',img='{$img}' where id = {$id}";
	
		if(mysql_query($sql)){
			echo '<script>location="index.php"</script>';
		}
	}
	
	
}
?>
<!DOCTYPE HTML>
<html lang="zh-CN">
<head>
	<meta charset="UTF-8"/>
	<meta http-equiv="X-UA-Compatible" content="IE=edge">
	<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
	<meta name="renderer" content="webkit">
	<title>完善用户资料</title>
	<!--[if lt IE 9]>
      <script src="//cdn.bootcss.com/html5shiv/3.7.2/html5shiv.min.js"></script>
      <script src="//cdn.bootcss.com/respond.js/1.4.2/respond.min.js"></script>
    <![endif]-->
	<script type="text/javascript" src="js/jquery-1.11.3.min.js" ></script>
	<script type="text/javascript" src="js/bootstrap.min.js"></script>
	<link rel="stylesheet" href="css/bootstrap.min.css" />
	<link rel="stylesheet" href="css/set.css" />
</head>
<body>

<!-- 导航条 -->

<div class="container">
	<div class="row userset">
		<div class="col-md-8 col-md-offset-2 cont">
			<form role="form" action="userall.php" method="post" enctype="multipart/form-data">
			<div class="row">
				<div class="col-md-7">
					<div class="form-group">
						<label>昵称：</label>
						<input type="text" class="form-control" name="nick" placeholder="xxx">
					</div>
					<div class="form-group">
						<label>手机：</label>
						<input type="text" class="form-control" name="tel" placeholder="xxx">
					</div>
					<div class="form-group">
						<label>邮箱：</label>
						<input type="text" class="form-control" name="email" placeholder="xxx">
					</div>
						<label>性别：</label>
					<label class="radio-inline">
						<input type="radio" name="gender" value="1"> 帅哥
					</label>
					<label class="radio-inline">
						<input type="radio" name="gender" value="0"> 美女
					</label>
				</div><!-- top_left -->
				<div  class="col-md-5">
					<div class="form-group">
						<div class="col-md-12">
							<label>头像：</label>
						</div>
						<div class="col-md-8 col-md-offset-2">
							<img class="img-circle" src="img/Klogo-web.png" width="100%"/>
							<input type="file" name="img">
						</div>
					</div>
				</div><!-- top_right -->
			</div>
			<div class="form-group">
				<label>个人简介：</label>
				<textarea class="form-control" rows="4" name="des"></textarea>
			</div><!-- but -->

			<div class="row">
				<div class="col-md-3 col-md-offset-6">
					<a href="index.html" class="btn btn-default btn-block">返&nbsp;&nbsp;回</a>
				</div>
				<div class="col-md-3">
					<input type="submit" class="btn btn-primary btn-block" value="保存">
				</div>
			</div>
			</form>
			
		</div>
	</div>
</div>

</body>
</html>
